package com.gsafety.libraryktx.base

import android.os.Bundle
import android.view.KeyEvent
import android.widget.ImageView
import android.widget.Toast
import androidx.appcompat.widget.Toolbar
import com.gsafety.library.Base.IBaseActivity
import com.gsafety.libraryktx.R
import com.gsafety.libraryktx.util.StatusUtils

/**
 * @author : lj
 * @date : 2020/12/29 10:21
 */
abstract class BaseActivity :IBaseActivity() {
    var toobar:Toolbar?=null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        toobar = findViewById(R.id.toolbar)
        toobar?.let {
            toobar?.setNavigationOnClickListener {
                finish()
            }
        }
        statusBar()
    }


    /**
     *  状态栏
     */
    open fun statusBar() {
        //--由于需要动态添加StatusBar,估必须在setContentView之后调用
        toobar?.let {
            StatusUtils.titleBar(this,it)
        }
    }

    protected fun showToast(msg:String) {
        Toast.makeText(this,msg + "",Toast.LENGTH_SHORT).show()
    }

    override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            val hasBack = handBack()
            if (!hasBack) {
                finish()
            }
            return true
        }
        return super.onKeyDown(keyCode, event)
    }


    open fun handBack(): Boolean {
        return false
    }

}